<template>
  <div class="commit">
    <!-- 详细评论 -->

    <mini-table>
      <a href="javascripr:;" class="hot-a" slot="left">全部评论({{ total }})</a>
      <div slot="right"></div>
      <div slot="body">
        <!-- 评论 -->
        <div class="all-commit" v-for="(item, index) in comments" :key="index">
          <div class="all-left">
            <el-image :src="item.user.avatarUrl" alt="" class="img" lazy />
          </div>
          <div class="all-right">
            <!-- 上 -->
            <div class="top">
              <a href="javascript:;">{{ item.user.nickname }}</a>
              <img
                class="rights"
                v-if="item.user.vipRights !== null"
                :src="vipImgs[item.user.vipRights.redVipLevel]"
                alt=""
              />

              ：{{ item.content }}
            </div>
            <!-- 中 -->
            <div class="center" v-if="item.beReplied.length !== 0">
              <a href="javascript:;">{{ item.beReplied['0'].user.nickname }}</a
              >：{{ item.beReplied['0'].content }}
            </div>
            <!-- 下 -->
            <div class="bottom">
              <div class="time">{{ item.timeStr }}</div>
              <div class="bottom-right">
                <i
                  class="icon"
                  @click="likeClick(item)"
                  :style="{
                    backgroundPosition: `${
                      item.liked ? '-170px 0' : '-150px 0'
                    }`
                  }"
                ></i>
                ({{ item.likedCount }})
                <span>|</span>
                <a href="javascript:;">回复</a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </mini-table>
  </div>
</template>

<script>
import { likeComment, loginStatus } from '@/api/api.js'
import MiniTable from './mini-table.vue'
// import {request} from '@/api/request.js'
// import axios from 'axios'

export default {
  components: { MiniTable },
  data() {
    return {
      // vip
      vipImgs: {
        1: 'https://p6.music.126.net/obj/wo3DlcOGw6DClTvDisK1/4213922817/9124/a83c/7eb7/6d7d81b608bfb56d7fb286bd8eb72346.png',
        2: 'https://p5.music.126.net/obj/wo3DlcOGw6DClTvDisK1/4213922900/5a1b/446b/b722/ec5a532c258824e8b59a45c166195e90.png',
        3: 'https://p6.music.126.net/obj/wo3DlcOGw6DClTvDisK1/4213922957/d393/4206/8928/a082dd9a7e7bb69e84b138b8df7bbcd0.png',
        4: 'https://p6.music.126.net/obj/wo3DlcOGw6DClTvDisK1/4213923065/dc4e/2b9c/7677/20a6644c6e3a093d7accce919ae7b169.png',
        5: 'https://p5.music.126.net/obj/wo3DlcOGw6DClTvDisK1/4213923094/81eb/9288/68a5/a427a0dbf899d616c3f715272a71ee59.png',
        6: 'https://p6.music.126.net/obj/wo3DlcOGw6DClTvDisK1/4213923139/f08a/c6ea/10ee/f7e2deef21937a1042e370c47525c956.png'
      }
    }
  },
  props: {
    comments: {
      type: Array,
      default() {
        return []
      }
    },
    total: {
      type: Number
    },
    info: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  methods: {
    // 点赞
    async likeClick(item) {
      if (
        !window.sessionStorage.getItem('token') &&
        !window.sessionStorage.getItem('cookie')
      ) {
        return this.$message.warning('请先登录')
      }
      const {
        data: { code: status }
      } = await loginStatus()

      if (!status) {
        this.$message.warning('请先登录')
        return this.$store.commit('editIsShow')
      }

      const res = await likeComment(this.info.type, item)
      console.log(res)
    }
  }
}
</script>

<style lang="scss" scoped>
.commit {
  padding: 0 40px;
  margin-top: 20px;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.all-commit {
  display: flex;
  padding: 15px 0;
  width: 100%;
  border-bottom: 1px dotted #ccc;
  .all-left {
    .el-image {
      display: block;
      width: 50px;
      height: 50px;
    }
  }
  .all-right {
    width: 100%;
    display: flex;
    flex-flow: column;
    justify-content: space-between;
    margin-left: 10px;
    .top {
      display: flex;
      justify-content: flex-start;
      a {
        display: inline-block;
        height: 16px;
        color: #0c73c2;
        &:hover {
          cursor: pointer;
          text-decoration: underline;
        }
      }
      img {
        display: block;
        width: 35px;
        height: 12px;
        margin: 0 5px;
      }
    }
    .center {
      padding: 8px 19px;
      background: #f4f4f4;
      border: 1px solid #dedede;
      margin: 10px 0;
      a {
        color: #0c73c2;
      }
    }
    .bottom {
      display: flex;
      justify-content: space-between;
      .time {
        color: #999;
        font-size: 12px;
      }
      .bottom-right {
        display: flex;

        .icon {
          display: block;
          width: 15px;
          height: 14px;
          background: url('https://s2.music.126.net/style/web2/img/icon2.png?117fc61d7994f13dd5435ad87aa68167')
            no-repeat 0 9999px;
          // background-position: -150px 0;
          &:hover {
            cursor: pointer;
            //  text-decoration: underline;
          }
        }
        span {
          margin: 0 10px;
        }
        a {
          color: #666;
        }
      }
    }
  }
}
</style>
